//
//  GMHTTPManage.m
//  GoodsManagement
//
//  Created by 车浩 on 2017/3/7.
//  Copyright © 2017年 CheHao. All rights reserved.
//

#import "GMHTTPManage.h"

@interface GMHTTPManage()

@property (nonatomic, strong) AFURLSessionManager *manager;

@end


@implementation GMHTTPManage


static GMHTTPManage *mgr;
+ (instancetype)manager{
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        mgr = [super manager];
        [mgr networkChange];
        mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/xml", @"text/plain", nil];
    });
    
    
    return mgr;
    
}

- (void)networkChange{
        
        _NetWork_Now = @"未知";
        
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        _manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
//        _manager.responseSerializer = [AFHTTPResponseSerializer serializer];
        
        [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
            
            switch (status) {
                case AFNetworkReachabilityStatusNotReachable:
                    _NetWork_Now = @"无网络";break;
                case AFNetworkReachabilityStatusReachableViaWWAN:
                    _NetWork_Now = @"3G/4G";break;
                case AFNetworkReachabilityStatusReachableViaWiFi:
                    _NetWork_Now = @"WiFi";break;
                case AFNetworkReachabilityStatusUnknown:
                default:
                    _NetWork_Now = @"未知";break;
            }
            
            NSLog(@"%@",_NetWork_Now);
        }];
        
        [[AFNetworkReachabilityManager sharedManager] startMonitoring];
        

}

+ (void)test{

    
    //    NSURLRequest *request =
    
    [[self manager] GET:@"http://www.cleanerair.com.cn/Api/Dervice/getMsgWeather"  parameters:@{@"province":@"102000"} progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSDictionary *string = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
        NSLog(@"%@",responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"Error: %ld", (long)error.code);
        NSLog(@"Error:%@",error);
    }];
    
  
}

@end
